use std::vec;


fn get_prime(n: u64) -> Vec<bool> {
    let mut prime = vec![true; (n + 1) as usize];
    for i in 2..n {
        if prime[i as usize] {
            let mut j = i * i;
            while j <= n {
                prime[j as usize] = false;
                j += i;
            }
        }
    }
    prime
}

fn judge(n: u64, primes: &Vec<bool>) -> bool {
    for i in 2..n {
        if primes[i as usize] {
            let remain = n - i;
            if remain % 2 == 0 {
                let remain = remain / 2;
                let root = (remain as f64).sqrt() as u64;
                if root * root == remain {
                    return true;
                }
            }
        }
    }
    false
}



pub fn goldbach_conjecture() -> u64 {
    // 两个符合条件的数分别是 5777 和 5993，所以先打表得到[1,10000]之间的素数
    let primes = get_prime(10000);
    let mut n = 9;
    let mut count = 0;
    let mut res = 0;
    while count < 2 {
        if !primes[n as usize] && !judge(n, &primes) {
            count += 1;
            res += n;
        } 
        n += 2;
    }
    res
}
